package Year22_Month04.day28;

import java.util.Arrays;

public class 反转字符串_two {
    public String reverseStr(String s, int k) {
        char[] arr = s.toCharArray();
        int len = arr.length;
        for(int i = 0;i < len;i += 2 * k){
            if(i + k - 1 < len){
                reveser(arr,i,i+k-1);
            }else{
                reveser(arr,i,len-1);
            }
        }
        return String.valueOf(arr);
    }

    public void reveser(char[] arr,int left,int right){
        while(left < right){
            char tmp = arr[left];
            arr[left] = arr[right];
            arr[right] = tmp;
            left++;
            right--;
        }
    }
}
